package demo2.demo2.client;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;

public class CxfClient3 {

    public static void main(String[] args) {
        CxfClient3.main3();
    }


    public static void main3() {
        Object retObj = null;

        Call call = null;

        Service service = new Service();

        //去掉缓存，以支持并发
        try {
            call = (Call) service.createCall();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e);
        }
        // 设置远程地址
        call.setTargetEndpointAddress("http://192.168.0.199:6036/realware/services/WSBankInterfaceService");
        // 清空操作
             call.clearOperation();
        // 清空头
             call.clearHeaders();

        Object[] body = new Object[]{"36017132112130011201811"};
        //  body[0] = "sssssssssssssssssssss";

        //   retObj = call.invoke("http://127.0.0.1/soap/user?wsdl","getUserName",body);
        retObj = invokeMethod(call, "TsQueryResponse", body);

        System.out.println(retObj.toString());


    }


    private static Object invokeMethod(Call call, String opName,
                                       Object... paras) {
        Object retObj = null;
        //设置要调用的方法
        call.setOperationName(opName);
        call.setOperationName(new QName("http://webservice.szpb.pt.grp", opName));
        call.addParameter("reqSerialNo", org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
        call.setReturnType(XMLType.XSD_STRING);
        //是否是soapaction这里需要看webservice是否要求如下格式，如果没有要求可以不添加此设置
        call.setUseSOAPAction(true);
        //该方法需要的参数
        Object[] objs = new Object[paras.length];
        int a = 0;
        for (Object objpara : paras) {
            objs[a] = objpara;
            a++;
        }
        try {
            //调用该方法
            retObj = call.invoke(objs);
        } catch (Exception e) {
            throw new RuntimeException("原因：" + e.getMessage(), e);
        }
        return retObj;
    }

}
